package com.amado.course36ByteStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;

public class S09ObjectInputStreamTest{

	public static void main(String[] args) {
		File file = new File("D:\\temp44\\student.txt");
		List<Student> studentList = readFile(file);
		for(Student stu:studentList){
			System.out.println(stu.getName()+"  "+stu.getAge());
		}
	}
	public static List<Student> readFile(File file) {
		ObjectInputStream output = null;
		try {
			output = new ObjectInputStream(new FileInputStream(file));
			List<Student> list = (List<Student>)output.readObject();
			return list;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				output.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	
}
